/*
	Editorial by HTML5 UP
	developed by liwei@abreaking
	Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
*/
//本站的ip地址
var WEB_IP = "192.168.137.1";

(function($) {
    skel.breakpoints({
        xlarge: '(max-width: 1680px)',
        large: '(max-width: 1280px)',
        medium: '(max-width: 980px)',
        small: '(max-width: 736px)',
        xsmall: '(max-width: 480px)',
        'xlarge-to-max': '(min-width: 1681px)',
        'small-to-xlarge': '(min-width: 481px) and (max-width: 1680px)'
    });

    $(function() {

        var	$window = $(window),
            $head = $('head'),
            $body = $('body');

        // Disable animations/transitions ...

        // ... until the page has loaded.
        $body.addClass('is-loading');

        $window.on('load', function() {
            setTimeout(function() {
                $body.removeClass('is-loading');
            }, 100);
        });

        // ... when resizing.
        var resizeTimeout;

        $window.on('resize', function() {

            // Mark as resizing.
            $body.addClass('is-resizing');

            // Unmark after delay.
            clearTimeout(resizeTimeout);

            resizeTimeout = setTimeout(function() {
                $body.removeClass('is-resizing');
            }, 100);

        });

        // Fix: Placeholder polyfill.
        $('form').placeholder();

        // Prioritize "important" elements on medium.
        skel.on('+medium -medium', function() {
            $.prioritize(
                '.important\\28 medium\\29',
                skel.breakpoint('medium').active
            );
        });

        // Fixes.

        // Object fit images.
        if (!skel.canUse('object-fit')
            ||	skel.vars.browser == 'safari')
            $('.image.object').each(function() {

                var $this = $(this),
                    $img = $this.children('img');

                // Hide original image.
                $img.css('opacity', '1');

                // Set background.
                $this
                /*.css('background-image', 'url("' + $img.attr('src') + '")')*/
                    .css('background-size', $img.css('object-fit') ? $img.css('object-fit') : 'cover')
                    .css('background-position', $img.css('object-position') ? $img.css('object-position') : 'center');

            });

        // Sidebar.
        var $sidebar = $('#sidebar'),
            $sidebar_inner = $sidebar.children('.inner');

        // Inactive by default on <= large.
        skel
            .on('+large', function() {
                $sidebar.addClass('inactive');
            })
            .on('-large !large', function() {
                $sidebar.removeClass('inactive');
            });

        // Hack: Workaround for Chrome/Android scrollbar position bug.
        if (skel.vars.os == 'android'
            &&	skel.vars.browser == 'chrome')
            $('<style>#sidebar .inner::-webkit-scrollbar { display: none; }</style>')
                .appendTo($head);

        // Toggle.
        if (skel.vars.IEVersion > 9) {
            $('<a id="navbar" href="#sidebar" class="toggle"></a>')
                .appendTo($sidebar)
                .on('click', function(event) {

                    // Prevent default.
                    event.preventDefault();
                    event.stopPropagation();
                    // Toggle.
                    $sidebar.toggleClass('inactive');

                });
        }
        skel.on('+xsmall',function(){
            $('#navbar').removeClass('toggle');
        })

        // Events.

        // Link clicks.
        $sidebar.on('click', 'a', function(event) {

            // >large? Bail.
            if (!skel.breakpoint('large').active)
                return;

            // Vars.
            var $a = $(this),
                href = $a.attr('href'),
                target = $a.attr('target');

            // Prevent default.
            event.preventDefault();
            event.stopPropagation();

            // Check URL.
            if (!href || href == '#' || href == '')
                return;

            // Hide sidebar.
            $sidebar.addClass('inactive');

            // Redirect to href.
            setTimeout(function() {

                if (target == '_blank')
                    window.open(href);
                else
                    window.location.href = href;

            }, 500);

        });

        // Prevent certain events inside the panel from bubbling.
        $sidebar.on('click touchend touchstart touchmove', function(event) {

            // >large? Bail.
            if (!skel.breakpoint('large').active)
                return;

            // Prevent propagation.
            event.stopPropagation();

        });

        // Hide panel on body click/tap.
        $body.on('click touchend', function(event) {

            // >large? Bail.
            if (!skel.breakpoint('large').active)
                return;

            // Deactivate.
            $sidebar.addClass('inactive');

        });

        // Scroll lock.
        // Note: If you do anything to change the height of the sidebar's content, be sure to
        // trigger 'resize.sidebar-lock' on $window so stuff doesn't get out of sync.

        $window.on('load.sidebar-lock', function() {

            var sh, wh, st;

            // Reset scroll position to 0 if it's 1.
            if ($window.scrollTop() == 1)
                $window.scrollTop(0);

            $window
                .on('scroll.sidebar-lock', function() {

                    var x, y;

                    // IE<10? Bail.
                    if (skel.vars.IEVersion < 10)
                        return;

                    // <=large? Bail.
                    if (skel.breakpoint('large').active) {

                        $sidebar_inner
                            .data('locked', 0)
                            .css('position', '')
                            .css('top', '');

                        return;

                    }

                    // Calculate positions.
                    x = Math.max(sh - wh, 0);
                    y = Math.max(0, $window.scrollTop() - x);

                    // Lock/unlock.
                    if ($sidebar_inner.data('locked') == 1) {

                        if (y <= 0)
                            $sidebar_inner
                                .data('locked', 0)
                                .css('position', '')
                                .css('top', '');
                        else
                            $sidebar_inner
                                .css('top', -1 * x);

                    }
                    else {

                        if (y > 0)
                            $sidebar_inner
                                .data('locked', 1)
                                .css('position', 'fixed')
                                .css('top', -1 * x);

                    }

                })
                .on('resize.sidebar-lock', function() {

                    // Calculate heights.
                    wh = $window.height();
                    sh = $sidebar_inner.outerHeight() + 30;

                    // Trigger scroll.
                    $window.trigger('scroll.sidebar-lock');

                })
                .trigger('resize.sidebar-lock');

        });

        // Menu.
        var $menu = $('.menu'),
            $menu_openers = $menu.children('ul').find('.opener');

        // Openers.
        $menu_openers.each(function() {

            var $this = $(this);

            $this.on('click', function(event) {

                // Prevent default.
                event.preventDefault();

                // Toggle.
                $menu_openers.not($this).removeClass('active');
                $this.toggleClass('active');

                // Trigger resize (sidebar lock).
                $window.triggerHandler('resize.sidebar-lock');

            });

        });

    });

})(jQuery);

function dateFormatByDatetime(datetime){
    var ts = new Date(datetime).getTime();
    return dateFormatByTimestamp(ts);
}

/**
 * by liwei
 * @param timestamp
 * @returns {string}
 */
function dateFormatByTimestamp(timestamp){
    var dateTime = new Date(timestamp);
    var nowTime = new Date();


    if(dateTime.getFullYear()!=nowTime.getFullYear()){
        return dateTime.getFullYear()+"年"+(dateTime.getMonth()+1)+"月"+dateTime.getDate()+"日";
    }
    if(nowTime.getDate()==(dateTime.getDate()+1)){	//昨天的

        return "昨天";
    }
    if(nowTime.getDate()==(dateTime.getDate()+2)){	//前天的
        return "前天";
    }

    if(nowTime.getDate() == dateTime.getDate()){	//同一天
        if(nowTime.getHours()>dateTime.getHours()){
            return (nowTime.getHours()-dateTime.getHours())+"小时之前";
        }
        if(nowTime.getMinutes()>dateTime.getMinutes()){
            return (nowTime.getMinutes()-dateTime.getMinutes())+"分钟之前";
        }
        if(nowTime.getSeconds()>dateTime.getSeconds()){
            return (nowTime.getSeconds()-dateTime.getSeconds())+"秒之前";
        }

    }
    var mouth = dateTime.getMonth()+1;
    var day = dateTime.getDate();
    return mouth+"月"+day+"日";
}
function record(page) {
    var cookie = document.cookie;
    if(cookie.indexOf("user")!=-1){
        //我本人的操作，就不再记录
        return;
    }
    var data = "page="+page;
    $.ajax({
        url:"http://"+WEB_IP+":8080/visitor/record",
        type:"post",
        data:data,
        xhrFields:{
            withCredentials:true       //可以发送cookie
        },
        success:function (data) {
            //成功
        }
    })
}
function lvbar(){
    var $sidebar = $('#sidebar');
    event.preventDefault();
    event.stopPropagation();

    // Toggle.
    $sidebar.toggleClass('inactive');

}